<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>管理员页面</title>
        <meta name="description" content="Charcoal is a free Bootstrap 4 UI kit build by @attacomsian at Wired Dots." />
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <!--Bootstrap 4-->
        <link rel="stylesheet" href="css/bootstrap.min.css">
    </head>
    <body>

        <nav class="navbar navbar-expand-md navbar-dark fixed-top sticky-navigation">
            <a class="navbar-brand font-weight-bold" href="#">在线oj系统</a>
            <div class="collapse navbar-collapse" id="topMenu">
                <ul class="navbar-nav ml-auto">
                    <li class="nav-item active">
                        <a class="nav-link page-scroll" href="login.html">登录 <span class="sr-only">(current)</span></a>
                    </li>              
            </div>
        </nav>

        <!--hero section-->
        <section class="bg-hero">
            <div class="container">
                <div class="row vh-100">
                    <div class="col-sm-12 my-auto text-center">
                        <h1>在线oj系统</h1>
                        <p class="lead text-capitalize my-4">
                            基于java Servlet 实现的oj系统
                        </p>
                        <a href="https://gitee.com/XieChaoBang/project.git" class="btn btn-outline-light btn-radius btn-lg">项目连接</a>
                    </div>
                </div>
            </div>
        </section>

        <!--components-->
        <section class="my-5 pt-5">
            <div class="container">
                        <div class="mt-3 mb-5">
                            
        
                            <h3>题目列表</h3>
                                
                            
                            
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>编号</th>
                                        <th>标题</th>
                                        <th>难度</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody id="problemTable">
                                    <!-- <tr>
                                        <td>1</td>
                                        <td>
                                            <a href="#">两数之和</a>    
                                        </td>
                                        <td>简单</td>
                                    </tr> -->
                                </tbody>
                            </table>
                        </div>
                        <div class="row mb-5" id="tooltip">
                            <div class="col-sm-12">
                                <div class="col-sm-6 pb-4">
                                    <a href="insertProblem.html">
                                        <button type="button" class="btn btn-success" data-toggle="tooltip" data-placement="left" title=""
                                        style="margin:20px;" data-original-title="Left sock" id="addproblem">
                                        新增题目
                                        </button>
                                    </a> 
                                    
                                </div>
                                   
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
        </section>

        <!--footer-->
        <section class="py-5 bg-dark">
            <div class="container">
                <div class="row">
                    <div class="col-md-6 offset-md-3 col-sm-8 offset-sm-2 col-xs-12 text-center">
                        <!-- <h3>Upgrade to Pro Version</h3>
                        <p class="pt-2">
                            We are working on <b>Charcoal Pro</b> which will be released soon. The pro version 
                            will have a lot more components, sections, icons, plugins and example pages. 
                            Join the waiting list to get notified when we release it (plus discount code).
                        </p>
                        <a class="btn btn-warning" href="https://wireddots.com/newsletter">Join Waiting List</a>
                        <hr class="my-5"/> -->
                        <p class="pt-2 text-muted">
                            &copy;  by 谢超帮
                            

                    </div>
                </div>
            </div>
        </section>

        <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
        <script src="js/app.js"></script>
        <script>
            // 在页面加载的时候，尝试从服务器获取题目列表，通过ajax 的方式来进行获取 
            function getProblems(){
                //1.先通过ajax 从服务器中获取题目列表
                jQuery.ajax({
                    url : "problems",
                    type:"get",
                    success:function(data,status){
                        //data是响应的数据 status 是响应的状态码
                        // 2.把得到的响应数据构造成HTML片段
                        makeProblemTable(data);
                    }
                });
            }

            // 通过这个函数来把数据装换成html页面片段
            function makeProblemTable(data){
                let problemTable = document.querySelector("#problemTable")
                for(let problem of data){
                    let tr = document.createElement("tr");
                    let tdId = document.createElement("td");
                    tdId.innerHTML = problem.id;
                    tr.appendChild(tdId);

                    let tdTitle = document.createElement("td");
                    let a = document.createElement("a");
                    a.innerHTML = problem.title;
                    a.href = "problemDetail.html?id=" + problem.id;
                    a.target='_blank';
                    tdTitle.appendChild(a);
                    tr.appendChild(tdTitle);

                    let tdLevel = document.createElement("td");
                    tdLevel.innerHTML = problem.level;
                    tr.appendChild(tdLevel);
                    problemTable.appendChild(tr);
                    let tddelete = document.createElement("td");

                    let adelete = document.createElement("a");
                    adelete.innerHTML = "删除";
                    adelete.href="deleteproblem?id=" +problem.id;
                    tddelete.appendChild(adelete);
                    tr.appendChild(tddelete);      
                }
            }
            getProblems();

            
            
        </script>
    </body>
</html>
